package neu.gprs.Action;

import neu.gprs.service.PosStatusService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author zhu_hui
 */
public class LoginAction extends ActionSupport {
    /**
     * SystemID
     */
    private static final long serialVersionUID = 1L;

    private String userName;
    private String password;
    private PosStatusService posStatusService;

    /**
     * @return the userName
     */
    public String getUserName() {
        return userName;
    }

    /**
     * @param userName
     *            the userName toset
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password
     *            the password toset
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * POS机Service
     * 
     * @param posStatusService
     */
    public void setPosStatusService(PosStatusService posStatusService) {
        this.posStatusService = posStatusService;
    }

    /**
     * 处理用户请求的excute()方法
     * 
     * @return 结果导航字符串
     * @throws Exception
     */
    public String execute() throws Exception {
        if (posStatusService.isLogin(userName, password)) {
            ActionContext.getContext().getSession().put("userName", getUserName());
            ActionContext.getContext().getSession().put("password", getPassword());
            if (!"admin".equals(this.userName)) {
                return LOGIN;
            } else {
                return SUCCESS;
            }
        }
        return INPUT;
    }
}
